<template>
    <div class="dashboard-container">
      <div class="container" :class="{ hContainer: tableData.length }">
        <!-- 搜索项 -->
        <div class="tableBar">
          <label style="margin-right: 5px">顾客姓名：</label>
          <el-input
            v-model="name"
            placeholder="请输入顾客姓名"
            style="width: 15%"
            clearable
            @clear="init"
            @keyup.enter.native="initFun"
            @input="initFun"
          />
          <label style="margin-left: 20px">手机号：</label>
          <el-input
            v-model="phone"
            placeholder="请填写手机号"
            style="width: 15%"
            clearable
            @clear="init"
            @keyup.enter.native="initFun"
            @input="initFun"
          />
          <el-button class="normal-btn continue" @click="init(true)">
            查询
          </el-button>
        </div>
        <el-table
          v-if="tableData.length"
          :data="tableData"
          stripe
          class="tableBox"
        >
          <el-table-column prop="name" label="顾客姓名" />
          <el-table-column prop="phone" label="手机号" />
          <el-table-column prop="summary" label="消费总金额" />
          <el-table-column prop="countMoney" label="消费次数" />
        </el-table>
        <Empty v-else :is-search="isSearch" />
        <el-pagination
          v-if="counts > 10"
          class="pageList"
          :page-sizes="[10, 20, 30, 40]"
          :page-size="pageSize"
          layout="total, sizes, prev, pager, next, jumper"
          :total="counts"
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
        />
      </div>
    </div>
  </template>
  
  <script lang="ts">
import { Component, Vue } from 'vue-property-decorator';
import HeadLable from '@/components/HeadLable/index.vue';
import InputAutoComplete from '@/components/InputAutoComplete/index.vue';
import Empty from '@/components/Empty/index.vue';
import { cutomerFeeInfo } from '@/api/order';

@Component({
  components: {
    HeadLable,
    InputAutoComplete,
    Empty,
  },
})
export default class extends Vue {
  private name = ''; // 姓名
  private phone = ''; // 手机号
  private summary = ''; // 总金额
  private countMoney = ''; // 总次数
  private counts: number = 0;
  private page: number = 1;
  private pageSize: number = 10;
  private tableData = [];
  private isSearch: boolean = false;

  created() {
    this.init();
  }

  initProp(val) {
    this.name = val;
    this.phone = val;
    this.initFun();
  }

  initFun() {
    this.page = 1;
    this.init(true); // 添加 true 参数表示这是搜索操作
  }

  private async init(isSearch?: boolean) {
    this.isSearch = isSearch;
    const params = {
      page: this.page,
      pageSize: this.pageSize,
      name: this.name ? this.name : undefined,
      phone: this.phone ? this.phone : undefined,
    };
    await cutomerFeeInfo(params)
      .then((res: any) => {
        if (String(res.data.code) === '1') {
          this.tableData = res.data.data && res.data.data.records || [];
          this.counts = res.data.data.total || 0;
        } else {
          this.$message.error('请检查输入是否正确');
        }
      })
      .catch((err) => {
        this.$message.error('请求出错了：' + err.message);
      });
  }

  private handleSizeChange(val: number) {
    this.pageSize = val;
    this.init();
  }

  private handleCurrentChange(val: number) {
    this.page = val;
    this.init();
  }
}
</script>

  <style lang="scss" scoped>
  .dashboard {
    &-container {
      margin: 30px;
      // height: 100%;
      min-height: 700px;
      .container {
        background: #fff;
        position: relative;
        z-index: 1;
        padding: 30px 28px;
        border-radius: 4px;
        // min-height: 650px;
        height: calc(100% - 55px);
  
        .tableBar {
          // display: flex;
          margin-bottom: 20px;
          justify-content: space-between;
  
          .tableLab {
            span {
              cursor: pointer;
              display: inline-block;
              font-size: 14px;
              padding: 0 20px;
              color: $gray-2;
              border-right: solid 1px $gray-4;
            }
          }
        }
  
        .tableBox {
          width: 100%;
          border: 1px solid $gray-5;
          border-bottom: 0;
        }
  
        .pageList {
          text-align: center;
          margin-top: 30px;
        }
        //查询黑色按钮样式
        .normal-btn {
          background: #333333;
          color: white;
          margin-left: 20px;
        }
      }
      .hContainer {
        height: auto !important;
      }
    }
  }
  
  .search-btn {
    margin-left: 20px;
  }
  
  .info-box {
    margin: -15px -44px 20px;
    p {
      display: flex;
      height: 20px;
      line-height: 20px;
      font-size: 14px;
      font-weight: 400;
      color: #666666;
      text-align: left;
      margin-bottom: 14px;
      &:last-child {
        margin-bottom: 0;
      }
      label {
        width: 100px;
        display: inline-block;
        color: #666;
      }
      .des {
        flex: 1;
        color: #333333;
      }
    }
  }
  
  .order-top {
    // height: 80px;
    border-bottom: 1px solid #e7e6e6;
    padding-bottom: 26px;
    padding-left: 22px;
    padding-right: 22px;
    // margin: 0 30px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    .order-status {
      width: 57.25px;
      height: 27px;
      background: #333333;
      border-radius: 13.5px;
      color: white;
      margin-left: 19px;
      text-align: center;
      line-height: 27px;
    }
    .status3 {
      background: #f56c6c;
    }
    p {
      color: #333;
      label {
        color: #666;
      }
    }
    .order-num {
      font-size: 16px;
      color: #2a2929;
      font-weight: bold;
      display: inline-block;
    }
  }
  
  .order-middle {
    .user-info {
      min-height: 140px;
      background: #fbfbfa;
      margin-top: 23px;
  
      padding: 20px 43px;
      color: #333;
      .user-info-box {
        min-height: 55px;
        display: flex;
        flex-wrap: wrap;
        .user-name {
          flex: 67%;
        }
        .user-phone {
          flex: 33%;
        }
        .user-getTime {
          margin-top: 14px;
          flex: 80%;
          label {
            margin-right: 3px;
          }
        }
        label {
          margin-right: 17px;
          color: #666;
        }
  
        .user-address {
          margin-top: 14px;
          flex: 80%;
          label {
            margin-right: 30px;
          }
        }
      }
      .user-remark {
        min-height: 43px;
        line-height: 43px;
        background: #fffbf0;
        border: 1px solid #fbe396;
        border-radius: 4px;
        margin-top: 10px;
        padding: 6px;
        display: flex;
        align-items: center;
        div {
          display: inline-block;
          min-width: 53px;
          height: 32px;
          background: #fbe396;
          border-radius: 4px;
          text-align: center;
          line-height: 32px;
          color: #333;
          margin-right: 30px;
          // padding: 12px 6px;
        }
        span {
          color: #f2a402;
          line-height: 1.15;
        }
      }
      .orderCancel {
        background: #ffffff;
        border: 1px solid #b6b6b6;
  
        div {
          padding: 0 10px;
          background-color: #e5e4e4;
        }
        span {
          color: #f56c6c;
        }
      }
    }
    .dish-info {
      // min-height: 180px;
      display: flex;
      flex-wrap: wrap;
      padding: 20px 40px;
      border-bottom: 1px solid #e7e6e6;
      .dish-label {
        color: #666;
      }
      .dish-list {
        flex: 80%;
        display: flex;
        flex-wrap: wrap;
        .dish-item {
          flex: 50%;
          margin-bottom: 14px;
          color: #333;
          .dish-num {
          }
          .dish-item-box {
            display: inline-block;
            width: 120px;
          }
        }
      }
      .dish-label {
        margin-right: 65px;
      }
      .dish-all-amount {
        flex: 1;
        padding-left: 92px;
        margin-top: 10px;
        label {
          color: #333333;
          font-weight: bold;
          margin-right: 5px;
        }
        span {
          color: #f56c6c;
        }
      }
    }
  }
  .order-bottom {
    .amount-info {
      // min-height: 180px;
      display: flex;
      flex-wrap: wrap;
      padding: 20px 40px;
      padding-bottom: 0px;
      .amount-label {
        color: #666;
        margin-right: 65px;
      }
      .amount-list {
        flex: 80%;
        display: flex;
        flex-wrap: wrap;
        color: #333;
        // height: 65px;
        .dish-amount,
        .package-amount,
        .pay-type {
          display: inline-block;
          width: 300px;
          margin-bottom: 14px;
          flex: 50%;
        }
        .send-amount,
        .all-amount,
        .pay-time {
          display: inline-block;
          flex: 50%;
          padding-left: 10%;
        }
        .package-amount {
          .amount-name {
            margin-right: 14px;
          }
        }
        .all-amount {
          .amount-name {
            margin-right: 24px;
          }
          .amount-price {
            color: #f56c6c;
          }
        }
        .send-amount {
          .amount-name {
            margin-right: 10px;
          }
        }
      }
    }
  }
  </style>
  
  <style lang="scss">
  .dashboard-container {
    .cancelReason {
      padding-left: 40px;
    }
    .cancelTime {
      padding-left: 50px;
    }
    .orderTime {
      padding-left: 50px;
    }
    td.operate .cell {
      .before,
      .middle,
      .after {
        height: 39px;
        width: 48px;
      }
    }
    td.operate .cell,
    td.otherOperate .cell {
      display: flex;
      flex-wrap: nowrap;
      justify-content: center;
    }
    .order-dialog {
      .el-dialog {
        max-height: 764px !important;
        display: flex;
        flex-direction: column;
        margin: 0 !important;
        position: absolute;
        top: 50%;
        left: 50%;
        transform: translate(-50%, -50%);
        max-height: calc(100% - 30px);
        max-width: calc(100% - 30px);
      }
      .el-dialog__body {
        height: 520px !important;
      }
    }
  }
  .el-dialog__body {
    padding-top: 34px;
    padding-left: 30px;
    padding-right: 30px;
  }
  .cancelDialog {
    .el-dialog__body {
      padding-left: 64px;
    }
    .el-select,
    .el-textarea {
      width: 293px;
    }
    .el-textarea textarea {
      height: 114px;
    }
  }
  .el-dialog__footer {
    .el-checkbox {
      float: left;
      margin-left: 40px;
    }
    .el-checkbox__label {
      color: #333333 !important;
    }
  }
  .empty-box {
    display: flex;
    align-items: center;
    justify-content: center;
    img {
      margin-top: 0 !important;
    }
  }
  </style>
  